
from openpyxl import Workbook,load_workbook
import pickle
import random
import copy
save_data_dir=r"D:\Personal\Desktop\beifen"
wb = load_workbook('D:/Personal/Desktop/InputData.xlsx', read_only=True)
ws=wb['Pucks']
wc=wb['Gates']

class plane():
    def __init__(self,Fa,Fd,P,A,D,no,name):
        self.Fa = Fa
        self.Fd= Fd
        self.P = P
        self.A = A
        self.D = D
        self.No=no
        self.name=name
class port():
    def __init__(self,Ha,Hd,G,no,name):
        self.Ha = Ha
        self.Hd= Hd
        self.G = G
        self.No=no
        self.S_pl=[]
        self.name=name
def save_pickle_data(save_data_dir, save_data, dataname):
    # 保存数据集
    with open(save_data_dir + "/" + dataname + ".pickle", "wb") as handle:
        # pickle.dump(save_data, handle)
        pickle.dump(save_data, handle, protocol=pickle.HIGHEST_PROTOCOL)
    handle.close()
 
 
def read_pickle_data(save_data_dir, dataname):
    with open(save_data_dir + "/" + dataname + ".pickle", 'rb') as handle:
        read_data = pickle.load(handle)
    handle.close()
    return read_data


if __name__=='__main__':
    #value0,PORTS_resalt,ST_resalt=read_pickle_data(save_data_dir,"登机口结果")
    #print("读取历史最优值为：",value0)
    #wb = Workbook()
    #ws = wb.active
    #for i in range(1,70):
    #    ws.cell(i,1).value=PORTS_resalt[i-1].No
    #    ws.cell(i,2).value=PORTS_resalt[i-1].name
    #    for j in range (3,len(PORTS_resalt[i-1].S_pl)+3):
    #        ws.cell(i,2*j).value=PORTS_resalt[i-1].S_pl[j-3].A
    #        ws.cell(i,2*j+1).value=PORTS_resalt[i-1].S_pl[j-3].D
    #ws.cell(71,2).value="临时登机口"
    #for i in range(3,len(ST_resalt)+3):
    #    j=i//7
    #    ws.cell(j+71,(i-3)%7+3).value=ST_resalt[i-3].name
    #wb.save('D:/Personal/Desktop/第一问输出.xlsx')

    value0,PORTS_resalt,ST_resalt=read_pickle_data(save_data_dir,"登机口结果")
    print("读取历史最优值为：",value0)
    wb = Workbook()
    ws = wb.active
    for i in range(1,70):
        ws.cell(i,1).value=PORTS_resalt[i-1].No
        ws.cell(i,2).value=PORTS_resalt[i-1].name
        ws.cell(i,3).value=PORTS_resalt[i-1].G
        ws.cell(i,4).value=len(PORTS_resalt[i-1].S_pl)
    ws.cell(71,2).value="临时登机口"
    for i in range(3,len(ST_resalt)+3):
        j=i//7
        ws.cell(j+71,(i-3)%7+3).value=ST_resalt[i-3].name
    wb.save('D:/Personal/Desktop/第一问输出.xlsx')

